﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using AmazeUI.bll.GetModel;
using AmazeUI.db;
using AmazeUI.Imodel;
using Jiekou.Com;
using WebCommon;

namespace AmazeUI.bll
{
    public class XtRoleBll : BaseBll
    {
        public IEnumerable<SelectListItem> GetSelectListItems()
        {
            return this.db.XtRole.ToList().Select(a => new SelectListItem()
            {
                Text = a.Name,
                Value = a.Id.ToString()
            }).ToList();
        }
        /// <summary>
        /// 功能list
        /// </summary>
        /// <returns></returns>
        public IEnumerable<XtPowers> GetXtPowersJsonList()
        {
            return this.db.XtPowers.ToList() ;
        }

        /// <summary>
        /// 角色list
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageListJs<XtRole2> List(int rows, int page)
        {
            var xrs = this.db.XtRole.ToList();
            var xtPowersJsonList = this.GetXtPowersJsonList().ToList();
            var pj = new PageListJs<XtRole>(xrs, rows, page);
            return pj.OpData(a => WebCommon.StringCommand.Static.ParentToSub<XtRole, XtRole2>(a));
        

        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="model"></param>
        public void AddXtRole(IXtRole model)
        {
            var xtRole = new XtRole(model);
            this.db.XtRole.Add(xtRole);
            this.db.SaveChanges();
        }

        /// <summary>
        /// 获取role角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public XtRole Edit(IXtRole model)
        {
            var xtRole = this.db.XtRole.Find(model.Id);
            xtRole.SetModel(model);
            this.db.SaveChanges();
            return xtRole;
        }
    }
}